from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import sys
sys.path.append("..")

from models.chat_models import ChatRoom
from views.chat_dialog import ChatDialog
from views.humiture_sensor_dialog import HumitureSensorDialog

from ui.Ui_others_widget import Ui_OthersWidget 


class OthersWidget(QWidget):
    
    def __init__(self, parent = None):
        super(OthersWidget, self).__init__(parent)
        self.ui = Ui_OthersWidget()
        self.ui.setupUi(self)
        
        self.ui.edit_server_ip.setText("192.168.33.222")
        self.ui.edit_server_port.setText("8001")
        
        self.init_ui()
        
    @pyqtSlot()
    def on_btn_enter_iot_clicked(self):
        server_ip = self.ui.edit_server_ip.text().strip()
        server_port = self.ui.edit_server_port.text().strip()
        if not server_ip or not server_port:
            QMessageBox.warning(self, "警告", "请输入服务器IP和端口号")
            return
        
        nickname = self.ui.edit_nickname.text().strip()
        if not nickname:
            QMessageBox.warning(self, "警告", "请输入昵称")
            return
        
        dialog = ChatDialog(self, server_ip, int(server_port), nickname)
        dialog.show()
        
        
    @pyqtSlot()
    def on_btn_humiture_clicked(self):
        dialog = HumitureSensorDialog(self)
        dialog.show()
        
        
    def init_ui(self):
        pass
    
if __name__ == '__main__':
    app = QApplication(sys.argv)

    w = OthersWidget()
    w.show()
    
    sys.exit(app.exec_())